package com.xmut.mall.manager.controller;

import com.xmut.mall.manager.annotation.CheckJwt;
import com.xmut.mall.manager.entity.MenuEntity;
import com.xmut.mall.manager.service.MenuService;
import com.xmut.mall.manager.utils.RespBean;
import com.xmut.mall.manager.vo.MenuVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("manager/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    /**
     * 添加菜单
     * @param menu
     * @return
     */
    @CheckJwt
    @PostMapping("/addMenu")
    public RespBean addMenu(@RequestBody MenuEntity menu){
        return menuService.addMenu(menu);
    }

    /**
     * 管理端登录时获取根据用户权限获取菜单
     * @param memberId
     * @return
     */
    @GetMapping("/getUserMenu/{memberId}")
    public RespBean getUserMenu(@PathVariable Long memberId){
        return menuService.getUserMenu(memberId);
    }

    /**
     * 获取一级菜单
     * @return
     */
    @GetMapping("/getMenuLevel1")
    public RespBean getMenuLevel1(){
        return menuService.getMenuLevel1();
    }

    /**
     * 获取菜单分类树
     * @return
     */
    @GetMapping("/getMenuTree/{id}")
    public RespBean getMenuTree(@PathVariable Long id){
        List<MenuVo> list = menuService.getMenuTree(id);
        return RespBean.success("获取成功",list);
    }
}
